﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace EZCRS.HCMS.msgctl.log
{
    public partial class loglist : System.Web.UI.Page
    {

        private const string STR_LOG_FILE_NAME = "log.txt";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                if (Request.QueryString["action"] != null)
                {
                    //get data
                    if (Request.QueryString["action"].ToLower() == "get")
                    {
                        int iPageIndex = 1;
                        int iPageSize = 15;

                        string strQuery = string.Empty;

                        if (!string.IsNullOrEmpty(Request.Params["page"]))
                            int.TryParse(Request.Params["page"], out iPageIndex);

                        if (!string.IsNullOrEmpty(Request.Params["rp"]))
                            int.TryParse(Request.Params["rp"], out iPageSize);

                        if (!string.IsNullOrEmpty(Request.Params["query"]))
                            strQuery = Request.Params["query"];

                        Response.Write(ReadLog(iPageIndex, strQuery, iPageSize));
                        Response.End();

                    }

                }
            }
        }

        private bool Delete(int PageIndex)
        {
            //StreamReader objReader = new StreamReader(strPah);

            return true;
        }



        private string ReadLog(int PageIndex, string Query, int PageSize)
        {
            return "";
            //string strPah = AppDomain.CurrentDomain.BaseDirectory + "msgctl\\" + STR_LOG_FILE_NAME;

            //StreamReader objReader = new StreamReader(strPah);

            //string strJson = "";

            //string strLine = "";

            //int iIndex = 0;

            //int iStartRow = (PageIndex - 1) * PageSize;
            //int iEndRow = (PageIndex - 1) * PageSize + PageSize;

            //while (strLine != null)
            //{
            //    strLine = objReader.ReadLine();

            //    if (strLine != null)
            //    {
            //        iIndex++;

            //        if (iIndex > iStartRow && iIndex <= iEndRow)
            //        {

            //            strJson += "{\"id\":\"" + iIndex.ToString() + "\",";

            //            strJson += "\"cell\":[";
            //            strJson += "\"" + iIndex.ToString() + "\",";
            //            strJson += "\"" + HttpUtility.HtmlEncode(strLine) + "\"";
            //            strJson += "]},";
            //        }
            //    }
            //}

            //objReader.Close();

            //strJson = "{\"total\":" + iIndex.ToString() + ",\"page\":" + PageIndex.ToString() + ",\"rows\":[" + strJson;

            //strJson = strJson.Replace("\r\n", " ");

            //strJson = strJson.TrimEnd(',');
            //strJson += "]}";

            //return strJson;
        }
    }
}
